<template>
  <div class="activity-container mtop">
    <m-header title="优惠活动" :preventBack="true" @navback="$router.replace({path: '/mine'})">
    </m-header>
    <scroller :on-refresh="refresh" :on-infinite="infinite">
      <div class="activity-list" v-if="activetyList && activetyList.length"
      :class="{'loaded-data': activetyList.length < 5, 'loadmore-data': activetyList.length < 10}">
        <div class="activity-item" v-for="(item, index) in activetyList"
          :key="index" @click="$router.push({ path: `/mine/activity/detail/${item.poster_id}` })">
          <img :src="item.pic" alt="">
          <div class="content">
            <div class="text">{{item.title}}</div>
            <div class="time">{{item.end_time}}</div>
          </div>
        </div>
      </div>
    </scroller>
    <div class="no-record"  v-if="!loading && !activetyList.length">
      <img src="../../../assets/imgs/icon-noattention@2x.png" alt="">
      <div class="desc">暂无优惠活动</div>
    </div>
  </div>
</template>
<script>
import { mapActions } from 'vuex';

export default {
  data () {
    return {
      pageNum: 1,
      isPull: false, // 下拉
      loading: true,
      activetyList: []
    }
  },
  mounted () {
    // this.getDatas(1);
  },
  methods: {
    ...mapActions({
      getPosterList: 'mine/getPosterList'
    }),
    refresh (done) {
      this.isPull = true;
      this.pageNum = 1;
      this.loading = true;
      this.getDatas(done);
    },
    infinite (done) {
      if (!this.isPull) {
        this.loading = true;
        this.getDatas(done);
      }
    },
    getDatas (done) {
      if (this.loading) {
        this.getPosterList({ page: this.pageNum }).then(res => {
          this.loading = false;
          let listData = res.list || [];
          if (listData.length) {
            if (this.isPull) {
              this.isPull = false;
              this.activetyList = [];
            }
            this.pageNum += 1;
            const listDatas = this.activetyList;
            this.activetyList = listDatas.concat(listData);
            if (this.pageNum < res.page.total) {
              done(true);
            } else {
              done(2); ;
            }
          } else {
            done(2);
          }
          // if (res) {
          //   const posterList = this.activetyList;
          //   const posterData = res.list || [];
          //   this.activetyList = posterList.concat(posterData);
          // }
        });
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .activity-container {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    background: #f7f7f7;
    &::-webkit-scrollbar{
      display: none;
    }
  }
  .activity-list {
    padding: 0.92rem 0.3rem 0.3rem;
    background: #f7f7f7;
    box-sizing: border-box;
    .activity-item {
      position: relative;
      margin-top: 0.3rem;
      border-radius: 0.1rem;
      height: 3.46rem;
      overflow: hidden;
      background: rgba(0, 0, 0, 0.3);
      img {
        display: block;
        width: 100%;
        // height: 100%;
      }
      .content {
        position: absolute;
        bottom: 0;
        width: 100%;
        height: 0.7rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 0.2rem;
        background: rgba(0, 0, 0, 0.4);
        box-sizing: border-box;
        .text {
          font-size: 0.3rem;
          color: #fff;
        }
        .time {
          font-size: 0.22rem;
          color: #fff;
        }
      }
    }
  }
  .no-record {
    position: fixed;
    width: 100%;
    top: 1.92rem;
    bottom: 0;
    height: 100%;
    text-align: center;
    background: #ffffff;
    img {
      display: block;
      width: 4.15rem;
      height: 3.22rem;
      margin: 0 auto;
      padding-top: 0.8rem;
    }
    .desc {
      margin-top: 0.3rem;
      font-size: 0.22rem;
      color: #919191;
    }
  }
</style>
